/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-16 17:01:25
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-17 10:20:43
 */
import 'package:flutter_data_center/model/camera/camera_model.dart';
import 'package:flutter_data_center/net/dio_utils.dart';
import 'package:get/get.dart';

class CameraController extends GetxController {
  int _total = 0;
  int get total => _total;

  void getCameraStatistics() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.lightStatistics,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _total = data['total'];
      update();
    }
  }

  // 菜单列表
  List<CameraItemModel> _cameraList = [];
  List get cameraList => _cameraList;
  void getCameras() async {
    _cameraList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.cameraList,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _cameraList.add(CameraItemModel.fromJson((item)));
      }
      update();
    }
  }

  CameraDetailModel _cameraDetail = CameraDetailModel(warnings: [], name: "监控");
  CameraDetailModel get cameraDetail => _cameraDetail;
  void getCameraDetail() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.cameraDetail,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _cameraDetail = CameraDetailModel.fromJson(data);
      update();
    }
  }
}
